package serveur;

import java.net.ServerSocket;
import java.net.Socket;
import javax.swing.JOptionPane;

public class ServerClient{
	
	private ServerSocket serverSocket;
	private Socket client;
	private int port;

	
	
	public ServerClient (int port){
		this.port = port;
		
	}
	
	public void start(){
		
		Thread thread;
		try{	
			
			System.out.println ("Starting the socket server at port: " + port);
			serverSocket = new ServerSocket(port);
			
			while(true){
				System.out.println("waiting .. ");
				client = serverSocket.accept();
				
				HTTPRequest httpReq = new HTTPRequest(client);
				thread = new Thread(httpReq);
				thread.start();
			}
			
		}catch(Exception e){
			System.out.println(e);
			JOptionPane.showMessageDialog(null, "Error server socket connection failed .. ");
		}
		
	}
	
	public static void main(String[] args){
		
			int defaultPort = 7777;
			
			ServerClient socketServer = new ServerClient(defaultPort);
			socketServer.start();
			
	}
	
}
